Split a string

Hi all,

i seach for a function to split a string by a delimiter

String: "Tree;Rubber;Door"

And i need to save all of them into a list or something, like string a is tree, string b is rubber and so on...

Here is my destroyed code :D

string se = "Tree;Rubber;Door"
string sub = ";"
int offset
int len

void test(string s)
{
        if (findPlainText(s, sub, offset, len, false)) 
        {
                st = s[0 : offset -1] "\n"
                sec =s[offset +1 :] "\n"
                print "1:" st "\n" 
                print "2:" sec "\n"
                print "____________________\n"
                test(sec)
                
        } 
        else 
        {
                // no delimiter found
                print "Failed to match"
        }
}

test(se)

Thank for help ...

 


meinhana - Mon Aug 29 08:08:43 EDT 2016

Re: Split a string
Wolfgang Uhr - Mon Aug 29 10:28:34 EDT 2016

As far as I know you have to initialize the variables offset and len and the error message tells you exact that.

Re: Split a string
meinhana - Tue Aug 30 02:31:37 EDT 2016

Wolfgang Uhr - Mon Aug 29 10:28:34 EDT 2016

As far as I know you have to initialize the variables offset and len and the error message tells you exact that.

I dont have an error message, i have an not required output :

1:Tree

2:Rubber;Door

____________________
1:Rubber

2:Door

____________________
Failed to match

Re: Split a string
meinhana - Tue Aug 30 02:41:09 EDT 2016

Well i found an option,

i write these strings into a skiplist :)

string se = "Tree;Rubber;Door"
string sub = ";"
int offset
int len
string st = ""
string sec = ""
string thr = ""
Skip sk = createString()

void test(string s)
{
        if (findPlainText(s, sub, offset, len, false)) 
        {
                st = s[0 : offset -1]
                sec =s[offset +1 :] 
                put(sk, st, st) 
                test(sec)
                
        } 
        else 
        {
                thr = s 
                put(sk, thr, thr) 
        }
}

test(se)

string k = ""
for k in sk do
{
        print "1: "k "\n"   
}